<?
class Rule_UniqueWithOwner extends Rule
{
    public $table;
    public $ownerid;
    public $error_message = "Значение уже существует";

    function __construct($name, $table, $ownerid, $error_message = "")
    {
        $this->name = $name;
        $this->table = $table;
        $this->ownerid = $ownerid;
        if ($error_message != "")
            $this->error_message = $error_message;
    }

    function Check($hash)
    {
        $count = DB::scalarSelect("select count(*) from $this->table where ownerid=" . $this->ownerid . " and $this->name = '" . DB::escape($hash[$this->name]) . "'");
        if ($count == 0)
            return true;
        return false;
    }
}
